subroutine rotate_molecular( alph, beta, gamm, inpos, outpos, n)
use prec
implicit none
   !----------------------------------------------------------------------------
   integer, intent(in) :: n
   real(q), intent(in) :: alph, beta, gamm, inpos(3,n)
   real(q), intent(out):: outpos(3,n)
   !----------------------------------------------------------------------------
   real(q) :: matX(3,3), matY(3,3), matZ(3,3), matT(3,3)
   real(q) :: sina, cosa, sinb, cosb, sinc, cosc
   !----------------------------------------------------------------------------
   sina = sin( alph )
   sinb = sin( beta )
   sinc = sin( gamm )
   cosa = cos( alph )
   cosb = cos( beta )
   cosc = cos( gamm )
   !
   matX = reshape( (/ 1.D0, 0.D0, 0.D0, 0.D0, cosa, sina, 0.D0, -sina, cosa/), &
   &               (/3,3/) )
   matY = reshape( (/ cosb, 0.D0, -sinb, 0.D0, 1.D0, 0.D0, sinb, 0.D0, cosb/), &
   &               (/3,3/) )
   matZ = reshape( (/ cosc, sinc, 0.D0, -sinc, cosc, 0.D0, 0.D0, 0.D0, 1.D0/), &
   &               (/3,3/) )
   matT = matmul( matmul(matX, matY), matZ )
   !
   outpos = matmul( matT, inpos )
   !
return
end subroutine
